import { useAppDispatch, useAppSelector } from "@/store/hooks";
import { submit } from "@/store/withdrawRecord/withdrawRecordAPI";
import { changeModal, changeSelectedRowKeys, getListAsync } from "@/store/withdrawRecord/withdrawRecordSlice";
import { Form, Input, Modal } from "antd";
import { useState } from "react";

export default function Review() {
    const [loading, setLoading] = useState<boolean>(false)
    const { modal, params } = useAppSelector(state => state.withdrawRecord)
    const dispatch = useAppDispatch()
    const [form] = Form.useForm()
    const handleClose = () => {
        form.resetFields()
        dispatch(changeModal({ open: false }))
    }
    const handleOk = async () => {
        try {
            const values = await form.validateFields()
            setLoading(true)
            submit({
                wd_status: 2,
                wd_list_str: JSON.stringify(modal.wd_list_str),
                reason: values.reason
            }).then(() => {
                handleClose()
                dispatch(getListAsync({ ...params }))
                dispatch(changeSelectedRowKeys([]))
            }).finally(() => setLoading(false))
        } catch (err) { }
    }
    return <Modal title='确认拒绝吗' open={modal.open} onCancel={handleClose} onOk={handleOk} confirmLoading={loading}>
        <Form form={form}>
            <Form.Item name='reason' label='原因' rules={[{ required: true, message: '必填' }]}>
                <Input.TextArea />
            </Form.Item>
        </Form>
    </Modal>
}